<?php

/**
 * This is the model class for table "product_skill_level".
 *
 * The followings are the available columns in table 'product_skill_level':
 * @property string $id
 * @property string $skill_id
 * @property string $skill_level
 * @property string $skill_time
 * @property string $skill_price
 */
class ProductSkillLevel extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return ProductSkillLevel the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'product_skill_level';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('skill_id, skill_level, skill_time, skill_price', 'required'),
            array('skill_id, skill_level, skill_gold,skill_time,skill_price', 'numerical'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, skill_id, skill_level, skill_time, skill_price', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'skill_id' => '技能ID',
            'skill_level' => '技能等级',
            'skill_time' => '时间(小时)',
            'skill_price' => '价格($)',
            'skill_gold' => '需要金币',
            'update_time' => '最后修改时间'
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('skill_id', $this->skill_id);
        $criteria->compare('skill_level', $this->skill_level);
        $pageSize = 10;
        if ($this->skill_id > 0)
            $pageSize = 10000;

        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                    'sort' => array(
                        'defaultOrder' => 'skill_id ASC, skill_level ASC',
                    ),
                    'pagination' => array(
                        'pageSize' => $pageSize
                    )
                ));
    }

    /**
     * 生成输入框
     * @author flwof
     * @param type $name
     * @param type $id
     * @param type $val 
     */
    public static function createInput($name, $id, $val) {
        echo CHtml::textField("{$name}_{$id}", $val, array('rel-id' => $id, 'rel-field' => $name, 'onchange' => "updateField(this)"));
    }

}